<?php
/**
 * ClassName: MemberInfoService
 * Description: 用户信息/家庭组成员信息service
 * @Author 周昌
 * @Create 2023/12/5 16:22
 */

namespace service\admin;


use libs\Tool;
use model\MemberModel;
use service\BaseService;

class MemberInfoService extends BaseService
{
    protected static $model='model\MemberInfoModel';

    //获取
    public static function getMemberInfo($id)
    {
        $info=self::$model::getInfo(['id'=>$id]);
        $member_info=MemberService::getFamilyGroup(['id'=>$info['member_id']])['data'];
        $info['family_group']=$member_info['family_group'];
        $info['phone']=$member_info['phone'];
        return $info;
    }


    //列表数据
    public static function getAjaxData($where)
    {
//        var_dump($where);
        $table = self::$model::order('id desc');
        return self::tableJsonData($table, $where, function ($data) {
            $data['height'] = $data['height'] ?: '';
            $data['weight'] = $data['weight'] ?: '';
            $data['sex_name'] = MemberService::$sex[$data['sex']];
            $data['relation_name'] = ArchivesService::$relation[$data['relation']];
            return $data;
        },function ($data){

            if(!empty($data)){
                // 批量获取家庭组
                $member_ids=array_column($data,'member_id');
                $family=MemberService::getMoreFamilyGroup([['id','in',$member_ids]]);
                foreach ($data as &$v){
                    $v['family_group']=isset($family[$v['member_id']])?$family[$v['member_id']]['family_group']:'';
                }
            }
            return $data;
        });
    }
}